package html.field.inputs;

import java.util.Map;

import html.field.Field;

public class Select implements Field {

	private StringBuffer style = new StringBuffer();
	private String name;
	private Map<String,String> valDispMap;

	@Override
	public Field css(String attr, String val) {
		if(style.toString().length()>0)
			style.append(";");
		style.append(attr+":"+val);
		return this;
	}
	
	public Select(String name,Map<String,String> valDispMap)
	{
		this.name=name;
		this.valDispMap = valDispMap;
	}

	@Override
	public String out() {
		StringBuffer sb = new StringBuffer();
		sb.append("<select name=\""+name+"\" style=\""+style+"\">");
		for(String key : valDispMap.keySet())
		{
			sb.append("<option value=\""+key+"\">"+valDispMap.get(key)+"</option>");
		}
		sb.append("</select>");
		return sb.toString();
	}

}
